//index.js
//获取应用实例
const app = getApp()
var config = require('../../config.js');

Page({
  data: {
    searchProdut:'',
    tabbar: {},
    productCategoryList:[],
    footWechat:[],
    imgPath: config.imgPath,
    topcontent:[],
    companyInfo:{},
    shuoming:{},
    about:{},
    autoplay: true,
    interval: 5000,
    duration: 500,
    heights: 200,
    indicatorDots:true,
    currentSwiper:0
  },
  swHeight: function (e) {
    var imgwidth = e.detail.width,
      imgheight = e.detail.height,
      ratio = imgwidth / imgheight;
    // //计算的高度值  
    var ws = wx.getSystemInfoSync().windowWidth;
    var viewHeight = (ws / ratio) * 0.9 + 60;
    this.setData({
      heights: viewHeight
    })
  },
  swiperChange: function (e) {
    this.setData({
      currentSwiper: e.detail.current
    })
  },
  onLoad: function () {
    app.editTabbar();
  },
  onShow:function (){
    this.loadInfo();
  },
  searchProdutInput(e){
    this.setData({
      searchProdut : e.detail.value
    })
  },
  
  search(){
    if(this.data.searchProdut == ''){
      wx.showToast({
        title: '请输入内容!',
        icon:'none'
      })
      return
    }
    let self = this
    wx.navigateTo({
      url: '../search/index?searchKey='+self.data.searchProdut,
    })
  },
  loadInfo() {
    let self = this
    app.request({
      url: 'api/common/getIndexInfo',
      method: "GET",
      data:{},
      success: function (res) {
        if (res.data != null) {
            self.setData({
              productCategoryList: res.data.category,
              topcontent: res.data.indexBanner,
              footWechat: res.data.footWechat,
              companyInfo:res.data.companyInfo,
              shuoming:res.data.shuoming,
              about:res.data.about

            })
          }
      }
    })
  }
})
